package com.hubu.admin.handler;

import com.hubu.admin.utils.Result;
import com.hubu.admin.utils.ResultCode;
import io.jsonwebtoken.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@ControllerAdvice(annotations = {RestController.class, Controller.class})
@Slf4j
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(value= DuplicateKeyException.class)
    public Result exceptionHandler(DuplicateKeyException e){
        log.error("发生SQL异常！原因是：{}",e.getMessage());
        return Result.fail(500,e.getMessage());
    }


    /**
     * 全局异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result err(Exception e) {
        log.error("全局异常处理:{}",e.getMessage());
        return Result.fail();


    }

}
